<template>
  <div class="progress-area">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item><router-link to="/">首页</router-link></el-breadcrumb-item>
      <el-breadcrumb-item><router-link to="/projects">项目列表</router-link></el-breadcrumb-item>
      <el-breadcrumb-item>{{ project?.name || '-' }}</el-breadcrumb-item>
    </el-breadcrumb>

    <div class="progress-header">
      <h1 class="project-title">{{ project?.name || '-' }}</h1>
      <div class="project-actions">
        <el-button 
          v-if="canUpdateProject"
          type="primary" 
          size="small" 
          @click="$emit('edit')"
        >
          <el-icon><Edit /></el-icon>
          编辑项目
        </el-button>
        <el-button 
          v-if="canDeleteProject"
          size="small" 
          @click="$emit('delete')"
        >
          删除项目
        </el-button>
      </div>
    </div>

    <div class="progress-bar-container">
      <div class="progress-info">
        <span>需求完成率</span>
        <span class="progress-percentage">{{ completionPercentage }}%</span>
      </div>
      <el-progress
        :percentage="completionPercentage"
        :color="progressColor"
        :status="completionStatus"
      />
      <div class="progress-details">
        <span>需求总数: {{ requirementTotal }}</span>
        <span>已完成: {{ requirementCompleted }}</span>
        <span>进行中: {{ requirementActive }}</span>
        <span>待处理: {{ requirementPending }}</span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import type { PropType } from 'vue'
import type { ProgressProps } from 'element-plus'
import { Edit } from '@element-plus/icons-vue'
import { usePermission } from '@/hooks/usePermission'

const { hasPermission } = usePermission()

// 权限计算属性
const canUpdateProject = computed(() => {
  return hasPermission('project:update') || 
         hasPermission('PROJECT_UPDATE') || 
         hasPermission('project:update_all') || 
         hasPermission('PROJECT_UPDATE_ALL')
})

const canDeleteProject = computed(() => {
  return hasPermission('project:delete') || 
         hasPermission('PROJECT_DELETE')
})

defineProps({
  project: {
    type: Object as PropType<Record<string, any> | null>,
    default: null
  },
  completionPercentage: {
    type: Number,
    required: true
  },
  progressColor: {
    type: String,
    required: true
  },
  completionStatus: {
    type: String as PropType<NonNullable<ProgressProps['status']>>,
    required: true
  },
  requirementTotal: {
    type: Number,
    default: 0
  },
  requirementCompleted: {
    type: Number,
    default: 0
  },
  requirementActive: {
    type: Number,
    default: 0
  },
  requirementPending: {
    type: Number,
    default: 0
  }
})

defineEmits(['edit', 'delete'])
</script>

<style scoped>
.progress-area {
  margin-bottom: 24px;
  padding: 28px 32px;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.8);
  transition: all 0.3s ease;
}

.progress-area:hover {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 24px 0 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.project-title {
  font-size: 28px;
  font-weight: 700;
  margin: 0;
  background: linear-gradient(135deg, #1e293b 0%, #475569 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.project-actions {
  display: flex;
  gap: 12px;
}

.project-actions :deep(.el-button) {
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.project-actions :deep(.el-button--primary) {
  box-shadow: 0 2px 8px rgba(64, 158, 255, 0.3);
}

.project-actions :deep(.el-button--primary):hover {
  box-shadow: 0 4px 12px rgba(64, 158, 255, 0.4);
  transform: translateY(-1px);
}

.progress-bar-container {
  margin-top: 24px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 15px;
  font-weight: 500;
  color: #475569;
}

.progress-percentage {
  font-weight: 700;
  font-size: 18px;
  color: #1e293b;
}

:deep(.el-progress-bar__outer) {
  border-radius: 10px;
  background-color: #f1f5f9;
  height: 12px !important;
}

:deep(.el-progress-bar__inner) {
  border-radius: 10px;
  transition: width 0.6s ease;
}

.progress-details {
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  font-size: 14px;
  color: #64748b;
  flex-wrap: wrap;
  gap: 16px;
}

.progress-details span {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  background: rgba(241, 245, 249, 0.6);
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.progress-details span:hover {
  background: rgba(241, 245, 249, 1);
  transform: translateY(-1px);
}

.overdue {
  color: #f56c6c;
  background: rgba(245, 108, 108, 0.1) !important;
  font-weight: 600;
}

:deep(.el-breadcrumb) {
  font-size: 14px;
}

:deep(.el-breadcrumb__inner) {
  color: #64748b;
  font-weight: 500;
  transition: color 0.2s ease;
}

:deep(.el-breadcrumb__inner:hover) {
  color: #409eff;
}

:deep(.el-breadcrumb__inner.is-link) {
  color: #64748b;
}

@media (max-width: 768px) {
  .progress-area {
    padding: 20px;
  }

  .progress-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .project-title {
    font-size: 24px;
  }

  .progress-details {
    flex-direction: column;
    gap: 8px;
  }
}
</style>

